<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

class CI_Working_date_entity{
	var $current_dbprefix = "";
	var $CI;
	var $id = 0;
	var $escort_id = 0;
	var $year = 0;
	var $month = 0;
	var $dates = "";
	
	function __construct() {
		$this->CI = &get_instance();
		$this->current_dbprefix = $this->CI->db->dbprefix;
		$this->CI->db->set_dbprefix('default_');
	}
	function __destruct() {
		$this->CI->db->set_dbprefix($this->current_dbprefix);
	}
	
	function setId($input){
		$this->id=$input;
	}
	function setEscortId($input){
		$this->escort_id =$input;
	}
	function setYear($input){
		$this->year =$input;
	}
	function setMonth($input){
		$this->month =$input;
	}
	function setDates($input){
		$this->dates =$input;
	}
	function getId(){
		return $this->id;
	}
	function getEscortId(){
		return $this->escort_id;
	}
	function getYear(){
		return $this->year;
	}
	function getMonth(){
		return $this->month;
	}
	function getDates(){
		return $this->dates;
	}
	
	function init($cmd, $input)
	{
		if($cmd == 'id'){
			$result = $this->CI->db->where('id',$input)->get(TBL_WORKING_DATE)->result();
		}else{
			return false;
		}
		if( !empty($result) ){
			$this->id = $result[0]->id;
			$this->escort_id = $result[0]->escort_id;
			$this->year = $result[0]->year;
			$this->month = $result[0]->month;
			$this->dates = $result[0]->dates;
			return $this;
		}
		return false;
	}
	function getWorkingDateList(){
		return $this->CI->db->get(TBL_WORKING_DATE)->result();
	}
	function save(){
		$this->CI->db->set('escort_id',$this->getEscortId());
		$this->CI->db->set('year',$this->getYear());
		$this->CI->db->set('month',$this->getMonth());
		$this->CI->db->set('dates',$this->getDates());
		$this->CI->db->insert(TBL_WORKING_DATE);
		return $this->CI->db->insert_id();
	}
	function update(){
		$this->CI->db->set('escort_id',$this->getEscortId());
		$this->CI->db->set('year',$this->getYear());
		$this->CI->db->set('month',$this->getMonth());
		$this->CI->db->set('dates',$this->getDates());
		return $this->CI->db->where('id', $this->id)->update(TBL_WORKING_DATE);
	}
	function delete($id){
		$this->CI->db->where('id',$id);
		$this->CI->db->delete(TBL_WORKING_DATE);
	}
}